 AddCSLuaFile( "cl_init.lua" ) 
 AddCSLuaFile( "shared.lua" ) 
   
 include('shared.lua') 
   
 local schdChase = ai_schedule.New( "AIFighter Chase" ) //creates the schedule used for this npc 
   
 	 
 	//  (first objective in task) 
 	schdChase:EngTask( "TASK_STORE_LASTPOSITION", 	0 ) 
 	schdChase:EngTask( "TASK_WEAPON_FIND", 				0 ) 
 	schdChase:EngTask( "TASK_WEAPON_PICKUP", 	0 ) 
 	 
 	// (second objectives in task) 
 	schdChase:AddTask( "FindEnemy", 		{ Class = "player", Radius = 20000 } ) 
 	schdChase:EngTask( "TASK_GET_PATH_TO_ENEMY", 	0 ) 
 	schdChase:EngTask( "TASK_SCRIPT_RUN_TO_TARGET", 				0 ) 
 	schdChase:EngTask( "TASK_RANGE_ATTACK1", 	0 ) 

 	// (third objective in task) 
 	schdChase:EngTask( "TASK_GET_PATH_TO_LASTPOSITION", 			0 ) 
 	schdChase:EngTask( "TASK_RUN_PATH", 			0 ) 
 	schdChase:EngTask( "TASK_RELOAD", 		0 ) 
 	schdChase:EngTask( "TASK_ADD_HEALTH", 		0 ) 
 	//schedule is looped till you give it a different schedule 
 	
 function ENT:SpawnFunction( ply, tr )

	if ( !tr.Hit ) then return end
	
	local SpawnPos = tr.HitPos + tr.HitNormal * 20
	
	local ent = ents.Create( "npc_rock" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	
	return ent
	
end

   
 function ENT:Initialize() 
   
 	self:SetModel( "models/props_wasteland/rockgranite03.mdl" ) 
 	 
 	self:SetHullType( HULL_LARGE ); 
 	self:SetHullSizeNormal(); 
 	 
 	self:SetSolid( SOLID_BBOX )  
 	self:SetMoveType( MOVETYPE_STEP ) 
 	 
 	self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_OPEN_DOORS | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_USE_SHOT_REGULATOR | CAP_AIM_GUN ) 
 	 
 	self:SetMaxYawSpeed( 5000 ) 
 	  
 	self:SetHealth(100) 
   
 end 
   
  function ENT:OnTakeDamage(dmg) 
   self:SetHealth(self:Health() - dmg:GetDamage()) 
   if self:Health() <= 0 then //run on death 
   self:SetSchedule( SCHED_FALL_TO_GROUND ) //because it's given a new schedule, the old one will end. 
   end 
  end  
   
   
 /*--------------------------------------------------------- 
    Name: SelectSchedule 
 //-------------------------------------------------------*/ 
 function ENT:SelectSchedule() 
   
 	self:StartSchedule( schdChase ) //run the schedule we created earlier 
   
 end